<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    .gray {
      color: gray;
    }

    .black {
      color: black;
    }
       
    </style>
</head>
<body>
    <input type="text" class="gray" value="请输入搜索关键字" id="txtSearch">
    <input type="button" value="搜索" id="btnSearch">  
    <script>
        var txtSearch = document.getElementById("txtSearch");
        
        txtSearch.onfocus = function (){
            if(txtSearch.value==="请输入搜索关键字"){
                txtSearch.value="";
                txtSearch.className="black";
            }
        }
        txtSearch.onblur = function (){
            if(txtSearch.value===""||txtSearch.value==="请输入搜索关键字"){
                txtSearch.value="请输入搜索关键字";
                txtSearch.className="gray";
            }
                
        }
        
    </script>   
</body>
</html>